package com.hy.mydesktop.client.component.factory;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.component.meta.AbstractComponetModelEnum;
import com.hy.mydesktop.client.component.meta.ShortcutModelEnum;
import com.hy.mydesktop.client.component.meta.TextFieldModelEnum;
import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.client.rpc.ServiceInvoker;
import com.hy.mydesktop.client.rpc.ServiceInvokerAsync;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceParameter;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceResult;
import com.hy.mydesktop.shared.rpc.util.ComponentControllerEnumConverter;

/**
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2010-11-17；时间：下午02:37:12</li>
 * <li>类型名称：RadioGroupFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class RadioGroupFactory {

	/**
	 * 
	 * <ul>
	 * <li>方法含义：</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-11-17；时间：下午下午02:37:45</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	public static RadioGroup createRadioGroup(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		return configureRadioGroup(gxtComponentMetaNodeModel);
		
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：配置文本框的属性</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午05:09:06</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static RadioGroup configureRadioGroup(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		
		final RadioGroup radioGroup=createDefaultRadioGroup();
//		text = AbstractComponetFactory.configureAbstractComponet(text, gxtComponentMetaNodeModel);
		 AbstractComponetFactory.configureAbstractComponet(radioGroup, gxtComponentMetaNodeModel);
		 AbstractComponetFactory.configureGxtToSeamServiceParameterModel(radioGroup, gxtComponentMetaNodeModel);

		
		if(gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase())!=null){
				//添加子控件
			 List<GxtComponentMetaNodeModel> list =(List<GxtComponentMetaNodeModel>)gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase());
			 for(int i=0;i<list.size();i++)
				{
					Radio radio=RadioFactory.createRadio(list.get(i));
					
					radioGroup.add(radio);
				}			
		}
		 
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.EMPTYTEXT.name().toLowerCase())!=null){
			//空值文本
			radioGroup.setEmptyText((String)gxtComponentMetaNodeModel.get(TextFieldModelEnum.EMPTYTEXT.name().toLowerCase()));
		}
		
		
		
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.VALUE.name().toLowerCase())!=null){
			//设置值
			//radioGroup.setValue((Boolean)gxtComponentMetaNodeModel.get(TextFieldModelEnum.VALUE.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.FIELDLABEL.name().toLowerCase())!=null){
			//设置标签
			radioGroup.setFieldLabel((String)gxtComponentMetaNodeModel.get(TextFieldModelEnum.FIELDLABEL.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.NAME.name().toLowerCase())!=null){
			//设置控件名
			radioGroup.setName((String)gxtComponentMetaNodeModel.get(TextFieldModelEnum.NAME.name().toLowerCase()));
		}
		
		//Listener<FieldEvent> textFieldListener = new Listener<FieldEvent>();
	   /* text.addListener(Events.OnClick, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
				 System.err.println(" text.setValue(reponse..........)............");
			}
		});*/
	   // System.err.println(" text.setValue(reponse..........)............");
		return radioGroup;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-11-17；时间：下午下午02:32:52</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	private static RadioGroup createDefaultRadioGroup(){
		RadioGroup radioGroup = new RadioGroup();
		radioGroup.setName("radioGroup");
		return radioGroup;
	}
}
